﻿using System;
using System.Xml;
using System.Xml.Serialization;

namespace ABC.XPath.Test.Models
{
	/// <summary>
	/// A transaction applied to an order.
	/// </summary>
	[XmlRoot("OrderTransaction", Namespace = "http://emsinet.com/schemas/Order/Data")]
	public class OrderTransaction
	{
		private Order _order;
		private DateTime _timestamp;
		private OrderTransactionType _type;
		private string _confirmationNumber;
		private XmlElement _clientRequest;

		/// <summary>
		/// Gets/sets the related order.
		/// </summary>
		[XmlIgnore]
		public Order Order
		{
			get { return _order; }
			set
			{
				_order = value;
				if (!(_order == null ||
					_order.Transactions.Contains(this)))
				{
					_order.Transactions.Add(_order.Transactions.Count, this);
				}
			}
		}

		/// <summary>
		/// Gets/set the transaction timestamp.
		/// </summary>
		[XmlElement("Timestamp", Namespace = "http://emsinet.com/schemas/Order/Data")]
		public DateTime Timestamp
		{
			get { return _timestamp; }
			set { _timestamp = value; }
		}

		[XmlElement("Type", Namespace = "http://emsinet.com/schemas/Order/Data")]
		public OrderTransactionType Type
		{
			get { return _type; }
			set { _type = value; }
		}

		/// <summary>
		/// Gets/set the transaction confirmation number.
		/// </summary>
		[XmlElement("ConfirmationNumber", Namespace = "http://emsinet.com/schemas/Order/Data")]
		public string ConfirmationNumber
		{
			get { return _confirmationNumber; }
			set { _confirmationNumber = value; }
		}

		/// <summary>
		/// Gets/sets the client request xml.
		/// </summary>
		[XmlElement("ClientRequest", Namespace = "http://emsinet.com/schemas/Order/Data")]
		public XmlElement ClientRequest
		{
			get { return _clientRequest; }
			set { _clientRequest = value; }
		}
	}
}
